#ifndef MAPWIDGET_H
#define MAPWIDGET_H
#include <QStackedWidget>
#include <QWidget>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QLineEdit>
#include <QGraphicsEllipseItem>
#include <QGraphicsTextItem>
#include "ui_map.h"
#include "algorithm.h"
#include "resultwidget.h"
#include "UserProfile.h"


class MapWidget : public QWidget {
    Q_OBJECT

public:
    explicit MapWidget(QWidget *parent = nullptr);
    void showDijkstraResult(const QString& result);
    void drawConnection(const QString &fromCity, const QString &toCity, const QColor &color, int offsetIndex);
    void loadJourneysFromDatabase();
    void drawArcConnection(const QString &fromCity, const QString &toCity, const QColor &color, int offsetIndex);

public slots:
    void updateMapConnections();

private:
    Ui::MapWidget *ui;  // 使用生成的 Ui 命名空间中的 MapWidget 类
    QGraphicsPixmapItem *mapItem;
    QGraphicsPixmapItem *d;  //装饰
    QList<QGraphicsEllipseItem*> cityMarkers;
    QGraphicsScene *scene;
    QStackedWidget *stackedWidget;

    UserProfile* userProfileWidget;

    void addCityMarker(const QString &name, const QPointF &position);
    void wheelEvent(QWheelEvent *event) override;  // 重写滚轮事件
    void zoomIn();  // 放大
    void zoomOut();  // 缩小
    void scaleView(qreal scaleFactor);  // 缩放视图

    MapWidget *mapWidget;
    QHash<QString, QPointF> cityCoordinates;

signals:
    void backMain();


};

#endif // MAPWIDGET_H
